import React, {Component} from "react";

import { connect } from "react-redux";

class App extends Component {

  render() {
    console.log(this.props);
    return (
      <div>
        <h1>react-redux</h1>
        <h2>store的初始值-----{this.props.num}</h2>

        <button onClick={()=> this.props.onIncrement(1)}>++</button>
        <button onClick={()=> this.props.onDecrement(1)}>--</button>
      </div>
    )
  }
}

let mapStateToProps = (state,oldProps)=>{
  console.log(state);
  return {
    ...state,
    ...oldProps,
    arr:['item1','item2']
  }
}

let mapDispatchToProps = (dispatch)=>{
  return {
    onIncrement: (count)=>dispatch({type:'add', count}),
    onDecrement: (count)=>dispatch({type:'deadd',count})
  }
}

export default  connect(
  mapStateToProps,
  mapDispatchToProps
)(App)